package createThread.cn.tedu.threaddemo.lock;

public class Test {
    public static int count = 0;
    private static final Object Lock = new Object();
    public static void main(String[] args) throws InterruptedException {

            Thread t1 = new Thread(()->{
                synchronized (Lock){
                    for (int i = 1; i <= 50000; i++) {
                        if(i == 10){
                            return;
                        }
                        count++;
                    }
                }
            });
            Thread t2 = new Thread(()->{
                synchronized (Lock){
                    for (int i = 1; i <= 50000; i++) {
                        count++;
                    }
                }
            });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(count);
    }
}
